package com.zgkxzx.mvpbase.utils;


import android.app.Activity;


import com.zgkxzx.mvpbase.ui.activity.BaseActivity;

import java.util.ArrayList;
import java.util.List;


/**
 * @创建者: zgkxzx
 * @创建时间: 2016-9-29
 * @描述: Activity工具类，主要管理activity
 */

public class ActivityUtil {
    private static final String TAG = ActivityUtil.class.getSimpleName();

    private static List<BaseActivity> activities = new ArrayList<>();

    /**
     * 添加activity到ActivityStack
     * @param activity activity实例
     */
    public static void addActivity(BaseActivity activity) {
        activities.add(activity);
    }

    /**
     * 移除activity
     * @param activity activity实例
     */
    public static void removeActivity(BaseActivity activity) {
        activity.finish();
        activities.remove(activity);
    }

    /**
     * 移除所有的activity
     */
    public static void removeAllActivities() {

        try {
            for (Activity activity : activities)
                if (activity != null)
                    activity.finish();
        } catch (Exception e) {
            // TODO: handle exception
        } finally {
            //System.exit(0);
        }

        //activities.clear();
    }

    /**
     * 退出app
     */
    public static void AppExit() {
        removeAllActivities();
    }
}
